home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 8: LINUX Games / Linux Cubed Series 8 - LINUX Games.iso / games / video / fly8111-.000 / fly8111- / fly8 / AMIGA / stick.c < prev    next >
C/C++ Source or Header  |  1979-12-31  |  3KB  |  152 lines

  1. /* --------------------------------- stick.c -------------------------------- */
  2.  
  3. /* This is part of the flight simulator 'fly8'.
  4.  * Author: Eyal Lebedinsky (eyal@ise.canberra.edu.au).
  5. */
  6.  
  7. /* Handler for the joy-stick as a pointing device.
  8.  * Amiga joy-stick routines by Michael Taylor
  9. */
  10.  
  11. #include "fly.h"
  12.  
  13.  
  14. #define PO        p->opt
  15. #define FA1D        PO[0]
  16. #define FA1F        PO[1]
  17. #define FA2D        PO[2]
  18. #define FA2F        PO[3]
  19. #define FOPTS        PO[13]
  20.  
  21. /* the following is the header for the joystick routines
  22.  *    
  23.  * JOY.asm
  24.  *
  25.  * subroutine for checking Amiga's gameports
  26.  * this source for a68k
  27.  *
  28.  * by Oliver Wagner, Landsberge 5, 4322 Sprockh÷vel, West Germany
  29.  *
  30.  * This is Public Domain, Enjoy!
  31.  *
  32. */
  33.  
  34. #define JOY_LEFT    1
  35. #define JOY_RIGHT    2
  36. #define JOY_UP        4
  37. #define JOY_DOWN    8
  38. #define JOY_FIRE    16
  39.  
  40. extern short    joy0 (), joy1 ();
  41.  
  42. /* Calibrate joy-stick. Paddle must be at center!
  43. */
  44. static int FAR
  45. cal (POINTER *p)
  46. {
  47.     p->c[FA1F] = p->c[FA2F] = 0;
  48.     p->a[FA1F] = p->a[FA2F] = 0;
  49.     p->l[FA1F] = p->l[FA2F] = 0;
  50.  
  51.     return (0);  /* this function always works */
  52. }
  53.  
  54. static int
  55. init (POINTER *p, char *options)
  56. {
  57.     if (get_arg (options, "linear"))
  58.         FOPTS &= ~USELOG;
  59.  
  60.     return (cal (p));
  61. }
  62.  
  63. /* Read joy-stick. Values are adjusted to 0...200.
  64. */
  65. static int FAR
  66. read (POINTER *p, int transfer)
  67. {
  68.     int        px, py;
  69.     unsigned int    x, y;
  70.     short        codeval;
  71.     char        btn[1];
  72.  
  73.     codeval = joy1 ();
  74.     
  75.     btn[0] = (codeval&JOY_FIRE && JOY_FIRE);    /* left button */
  76.  
  77.     x = -1*((codeval&JOY_LEFT) && JOY_LEFT) +
  78.         1*((codeval&JOY_RIGHT) && JOY_RIGHT);    /* range is -1 to 1 */
  79.          
  80.     y = -1*((codeval&JOY_DOWN) && JOY_DOWN) +
  81.         1*((codeval&JOY_UP) && JOY_UP);        /* range is -1 to 1 */
  82.  
  83. calcpos:
  84.     px = FA1F;
  85.     py = FA2F;
  86.  
  87. #define    REF    100        /* expected full range */
  88. #define    EDGE    10        /* movement increment  */
  89.  
  90.     p->a[px] += x * EDGE * FA1D;
  91.     if (p->a[px] > REF)
  92.         p->a[px] = REF;
  93.     else if (p->a[px] < -REF)
  94.         p->a[px] = -REF;
  95.     p->a[py] += y * EDGE * FA2D;
  96.     if (p->a[py] > REF)
  97.         p->a[py] = REF;
  98.     else if (p->a[py] < -REF)
  99.         p->a[py] = -REF;
  100.  
  101.     if (transfer) {
  102.         p->l[px] = p->a[px];
  103.         p->l[py] = p->a[py];
  104.     }
  105.  
  106.     do_btns (p, btn, rangeof (btn));
  107.  
  108.     return (0);
  109. }
  110.  
  111. static void FAR
  112. term (POINTER *p)
  113. {}
  114.  
  115. static int FAR
  116. center (POINTER *p)
  117. {
  118.     p->a[FA1F] = p->a[FA2F] = 0;
  119.     p->l[FA1F] = p->l[FA2F] = 0;
  120.  
  121.     return (0);
  122. }
  123.  
  124. struct PtrDriver PtrAstick = {
  125.     "ASTICK",
  126.     0,
  127.     cal,            /* init */
  128.     term,
  129.     cal,
  130.     center,
  131.     read,
  132.     std_key
  133. };
  134.  
  135. struct PtrDriver PtrBstick = {
  136.     "BSTICK",
  137.     0,
  138.     cal,            /* init */
  139.     term,
  140.     cal,
  141.     center,
  142.     read,
  143.     std_key
  144. };
  145.  
  146. #undef PO
  147. #undef FA1D
  148. #undef FA1F
  149. #undef FA2D
  150. #undef FA2F
  151. #undef FOPTS
  152.